<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 100px;
            position: absolute;
            left: 0px;
            top: 0px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <script>
        // function move(aaa, bbb, ccc, ddd) {
        //     function fn() {
        //         var num = parseInt(getComputedStyle(aaa)[ccc])
        //         console.log(num)
        //         var speed = bbb < num ? -1 : 1
        //         if (num == bbb) {
        //             ddd && ddd()
        //         } else {
        //             num += speed
        //             aaa.style[ccc] = num + "px"
        //             requestAnimationFrame(fn)
        //         }
        //     }
        //     fn()
        // }
        // var box = document.querySelector(".box")
        // move(box, 1000, "left")
        var box = document.querySelector(".box")
        function move(aaa, bbb, ccc) {
            function fn() {
                var num = parseInt(getComputedStyle(aaa)[ccc]);
                console.log(num);
                // var speed = 1;
                num += 1
                console.log(num);
                aaa.style[ccc] = num + "px"
                requestAnimationFrame(fn)
            }
            fn()
        }
        move(box, 1000, "left")
    </script>
</body>

</html>